﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WHC.Hotel.BLL;
using WHC.Hotel.Entity;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.UI.Report
{
    public partial class KTVBackConsumptionReport : BaseForm
    {
        public KTVBackConsumptionReport()
        {
            InitializeComponent();
        }

        private void KFCheckoutReport_Load(object sender, EventArgs e)
        {
            this.winGridView1.ProgressBar = this.toolStripProgressBar1.ProgressBar;
            this.winGridView1.AppendedMenu = this.contextMenuStrip1;

            this.dtStart.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            this.dtEnd.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));

        }

        private void BindData()
        {
            #region 添加别名解析
            //RoomNo,ItemName,Reason,Price,Discount,DiscountPrice,Quantity,Amount,OrderTime,Creator
            this.winGridView1.AddColumnAlias("BillNumber", "账单号");
            this.winGridView1.AddColumnAlias("RoomNo", "包间号");
            this.winGridView1.AddColumnAlias("ItemName", "项目名称");
            this.winGridView1.AddColumnAlias("Reason", "退单原因");
            this.winGridView1.AddColumnAlias("Price", "单价");
            this.winGridView1.AddColumnAlias("Discount", "打折比例");
            this.winGridView1.AddColumnAlias("DiscountPrice", "折后单价");
            this.winGridView1.AddColumnAlias("Quantity", "数量");
            this.winGridView1.AddColumnAlias("Amount", "应收金额");
            this.winGridView1.AddColumnAlias("OrderTime", "入账时间");
            this.winGridView1.AddColumnAlias("Creator", "记账人");

            #endregion

            SearchCondition condition = new SearchCondition();
            condition.AddCondition("c.OrderTime", this.dtStart.Value.ToString(), SqlOperator.MoreThanOrEqual)
                .AddCondition("c.OrderTime", this.dtEnd.Value.ToString(), SqlOperator.LessThanOrEqual)
                .AddCondition("c.RoomNo", this.txtRoomNo.Text, SqlOperator.Like)
                .AddCondition("r.BillNumber", this.txtBillNumber.Text, SqlOperator.Like);
            string filter = condition.BuildConditionSql(DatabaseType.SqlServer);

            this.winGridView1.PrintTitle = Portal.gc.gAppUnit + " -- " + "KTV消费退单明细查询";
            this.winGridView1.DisplayColumns = "BillNumber,RoomNo,ItemName,Reason,Price,Discount,DiscountPrice,Quantity,Amount,OrderTime,Creator";
            DataTable dt = BLLFactory<KTVBackConsumerList>.Instance.GetBackConsumptionReport(filter);
            this.winGridView1.DataSource = dt.DefaultView;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        private void menu_InRefresh_Click(object sender, EventArgs e)
        {
            BindData();
        }

        private void txtRoomNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                BindData();
            }
        }
    }
}
